import axios from 'axios'

const http = axios.create({
  baseURL: 'http://127.0.0.1:8888/api/private/v1/',
  timeout: 1000
})

http.interceptors.request.use((config) => {
  const token:any = sessionStorage.getItem('hmds-token')
  if (token) {
    config.headers = {
      ...config.headers,
      Authorization: token
    }
  }
  return config
}, (err) => {
  return Promise.reject(err)
})

axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

// 添加响应拦截器
http.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response.data;
  }, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  });

export default http